import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.StyleConstants;

public class TypeInTest extends JApplet
{
    boolean isStandalone = false;
    JPanel jPanel1 = new JPanel();
    BorderLayout borderLayout1 = new BorderLayout();
    JTextPane jTextPane1 = new JTextPane();
    BorderLayout borderLayout2 = new BorderLayout();
    /**Get a parameter value*/
    public String getParameter(String key, String def)
    {
        return isStandalone ? System.getProperty(key, def) :
            (getParameter(key) != null ? getParameter(key) : def);
    }

    /**Construct the applet*/
    public TypeInTest()
    {
    }
    /**Initialize the applet*/
    public void init()
    {
        try
        {
            jbInit();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    /**Component initialization*/
    private void jbInit() throws Exception
    {
        this.setSize(new Dimension(400,300));
        this.getContentPane().setLayout(borderLayout1);
        jTextPane1.setEditable(false);
        jTextPane1.setCaretColor(Color.white);
        jTextPane1.setVerifyInputWhenFocusTarget(false);
        jTextPane1.setSelectedTextColor(Color.red);
        jTextPane1.setSelectionColor(Color.white);
        jTextPane1.setForeground(Color.white);
        jTextPane1.setText("jTextPane1");
        jTextPane1.addKeyListener(new TypeInTest_jTextPane1_keyAdapter(this));
        jTextPane1.addMouseListener(new TypeInTest_jTextPane1_mouseAdapter(this));
        jTextPane1.setHighlighter(null);
        jPanel1.setLayout(borderLayout2);
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.addKeyListener(new TypeInTest_jPanel1_keyAdapter(this));
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        jPanel1.add(jTextPane1, BorderLayout.CENTER);
    }
    /**Start the applet*/
    private DefaultStyledDocument dsd = new DefaultStyledDocument();
	private SimpleAttributeSet attrs = new SimpleAttributeSet();
    private String textString = "Typein the missing word.";

    public void start()
    {
        try
        {

        StyleConstants.setFontFamily(attrs, "Serif");
		StyleConstants.setFontSize(attrs, 24);
        StyleConstants.setAlignment(attrs, StyleConstants.ALIGN_CENTER);
        StyleConstants.setBold(attrs, true);
        StyleConstants.setForeground(attrs, Color.blue);

        dsd.insertString(0, "\n" + textString + "\n\n", attrs);
        int length = dsd.getLength();
        dsd.insertString(length, textString, attrs);

        dsd.setParagraphAttributes(0, dsd.getLength(), attrs, false);
        jTextPane1.setDocument(dsd);
        Highlighter h = jTextPane1.getHighlighter();
        System.err.println("Highlighter = " + h.toString());
        }
        catch(Exception e)
        {
            System.err.println("Exception: " + e.toString());
        }


    }
    /**Stop the applet*/
    public void stop()
    {
    }
    /**Destroy the applet*/
    public void destroy()
    {
    }
    /**Get Applet information*/
    public String getAppletInfo()
    {
        return "Applet Information";
    }
    /**Get parameter info*/
    public String[][] getParameterInfo()
    {
        return null;
    }
    /**Main method*/
    public static void main(String[] args)
    {
        TypeInTest applet = new TypeInTest();
        applet.isStandalone = true;
        JFrame frame = new JFrame();
        //EXIT_ON_CLOSE == 3
        frame.setDefaultCloseOperation(3);
        frame.setTitle("Applet Frame");
        frame.getContentPane().add(applet, BorderLayout.CENTER);
        applet.init();
        applet.start();
        frame.setSize(400,320);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
        frame.setVisible(true);
    }

    //static initializer for setting look & feel
    static
    {
        try
        {
            //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
           
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        }
        catch(Exception e)
        {
        }
    }

    void jTextPane1_keyReleased(KeyEvent e)
    {
        System.err.println("Key Released");
    }

    void jTextPane1_mouseReleased(MouseEvent e)
    {
        //e.consume();
        System.err.println("Mouse Released");
        //jTextPane1.getHighlighter().removeAllHighlights();
    }

    void jPanel1_keyReleased(KeyEvent e)
    {
        System.err.println("Key Released");
    }

    void jTextPane1_keyPressed(KeyEvent e)
    {
        System.err.println("Key Pressed");
    }

    void jTextPane1_keyTyped(KeyEvent e)
    {
        System.err.println("Key Typed");
    }

    void jTextPane1_mouseEntered(MouseEvent e)
    {

    }

    void jTextPane1_mouseClicked(MouseEvent e)
    {
        //e.consume();
        System.err.println("Mouse Clicked");
               // jTextPane1.getHighlighter().removeAllHighlights();
    }
}
